﻿using System.Collections;
using System.Web.Mvc;
using NUnit.Framework;
using TeamsPortal.DataAccess;
using TeamsPortal.Web.Controllers;


namespace TeamsPortal.Tests.Controllers
{
	//[CodedUITest]
	[TestFixture]
    public class PageContentsControllerTest
	{
		[Test]
		public void PageContent_Add_Edit_List_Detail_Delete_Test()
		{
			PageContentsController controller = new PageContentsController();

			PageContent content = new PageContent()
			{
				Title = "Dummy Test Content"
				,Body = "<p>Hello world</p>"
			};
			PageContent contentFail = new PageContent();
			#region Add
			var result = controller.Add(content);
            Assert.IsInstanceOf<RedirectToRouteResult>(result);
			Assert.IsNotNull(content.ShortName);

			controller = new PageContentsController();
			result = controller.Add(contentFail);
			//Must return to the view
            Assert.IsInstanceOf<ViewResult>(result);
			#endregion

			#region Edit
			content.Title += " (Edited)";
			controller = new PageContentsController();
			result = controller.Edit(content.ShortName, content);
            Assert.IsInstanceOf<RedirectToRouteResult>(result);

			controller = new PageContentsController();
			result = controller.Edit(content.ShortName, contentFail);
			//Must return to the view
            Assert.IsInstanceOf<ViewResult>(result);
			#endregion

			#region List and Detail
			result = controller.Detail(content.ShortName, false);
            Assert.IsInstanceOf<ViewResult>(result);
			Assert.IsNotNull(controller.ViewData.Model);
			//List
			result = controller.List();
            Assert.IsInstanceOf<ViewResult>(result);
			Assert.IsTrue(((IList)controller.ViewData.Model).Count > 0);
			#endregion

			#region Delete
			result = controller.Delete(content.ShortName);
            Assert.IsInstanceOf<JsonResult>(result);
			#endregion
		}
	}
}